﻿package fj.pv3d
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.cameras.*;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.render.BasicRenderEngine;

	public class FJ3DScene extends MovieClip
	{
		public var viewport:Viewport3D;
		public var renderer:BasicRenderEngine;
		public var scene:Scene3D;
		public var camera:Camera3D;

		private var _render:Boolean;

		public function FJ3DScene ():void
		{
			viewport = new Viewport3D( 955, 600, true, true );
			renderer = new BasicRenderEngine();
			scene = new Scene3D();
			camera = new Camera3D();
			_render = true;

			addChild ( viewport );
			addEventListener ( Event.ENTER_FRAME, renderLoop );
		}
		public function set render ( b:Boolean ):void
		{
			if (b) {
				addEventListener ( Event.ENTER_FRAME, renderLoop );
			} else {
				removeEventListener ( Event.ENTER_FRAME, renderLoop );
			}
		}
		public function renderLoop ( e:Event ):void
		{
			renderer.renderScene ( scene, camera, viewport);
		}
	}
}